<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title></title>
		<script type="text/javascript" src="../../js/boot.js"></script>
	</head>

	<body>
		<div style="width:800px;">
			<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
				<table style="width:100%;">
					<tr>
						<td style="width:100%;">
							<a class="mini-button" iconCls="icon-search" onclick="scan()" plain="true">重新扫描</a>
							<!--<span class="separator"></span>
							<a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a>-->
						</td>
					</tr>
				</table>
			</div>
		</div>

		<div class="mini-fit">
			<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" showPager="false" allowCellEdit="true" allowCellSelect="true" editNextOnEnterKey="true" editNextRowCell="true">
				<div property="columns">
					<div field="index" type="indexcolumn" width="10"></div>
					<div field="name" headerAlign="center" width="200">类名称</div>
					<div field="start" headerAlign="center" width="50" renderer="onRenderer">开机启动</div>
				</div>
			</div>
		</div>

		<div id="editWin" title="设置启动参数" class="mini-window" title="" style="width:460px;height:500px;" showShadow="true" showToolbar="true" showModal="true" allowResize="true" allowDrag="true">
			<div style="width:100%;">
				<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
					<table style="width:100%;">
						<tr>
							<td style="width:100%;">
								<a class="mini-button" iconCls="icon-save" onclick="saveData()" plain="true">保存</a>
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="mini-fit">
				<div id="fieldGrid" class="mini-datagrid" style="width:100%;height:100%;" allowCellEdit="true" allowCellSelect="true" editNextOnEnterKey="true" editNextRowCell="true">
					<div property="columns">
						<div field="index" type="indexcolumn" width="40"></div>
						<div field="key" headerAlign="center" width="100">属性名</div>
						<div field="val" name="val" headerAlign="center" width="300">属性值
							<input property="editor" class="mini-textbox" style="width:100%;" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>

	<script type="text/javascript">
		var START_STATUS = [{
			id: true,
			text: '启动'
		}, {
			id: false,
			text: '不启动'
		}];

		miniInit();

		var gridData = null;
		var datagrid = mini.get("datagrid");
		http.get("/admin/boot/getStartList.do", function(page) {
			if(page.success) {
				gridData = page.data;
				datagrid.setData(gridData);
			}
		});

		function onRenderer(e) {
			for(var i = 0, l = START_STATUS.length; i < l; i++) {
				var g = START_STATUS[i];
				if(g.id == e.value) return g.text;
			}
			return "";
		}

		var editWin = mini.get("editWin");
		var fieldGrid = mini.get("fieldGrid");

		datagrid.on("rowdblclick", function(e) {
			var record = e.record,
				column = e.column,
				field = e.field,
				value = e.value;
			var data = {
				"name": record.name
			};
			// debugger
			http.post("/admin/boot/getStartDetail.do", data, function(page) {
				if(page.success) {
					fieldGrid.setData(page.data);
					editWin.showAtPos('center', 'middle');
				}
			});
		});

		function addRow() {
			var newRow = {};
			var data = datagrid.getData();
			datagrid.addRow(newRow, data.length);
		}

		function removeRow() {
			var rows = datagrid.getSelecteds();
			if(rows.length > 0) {
				datagrid.removeRows(rows, true);
			}
		}

		function saveData() {
			mini.mask({
				el: document.body,
				cls: 'mini-mask-loading',
				html: '数据保存中...'
			});
			// debugger
			var data = {};
			var list = fieldGrid.getData();
			for(var i = 0; i < list.length; i++) {
				data[list[i].key] = list[i].val;
			}
			http.post("/admin/boot/saveStartDetail.do", data, function(page) {
				mini.unmask();
				if(page.success) {
					mini.alert("保存成功", "提示", null);
				} else {
					mini.alert(page.message, "保存失败", null);
				}
			});
		}
	</script>

</html>